/*
 * CaminhaoCadastrar.java
 *
 * Created on 16/02/2009, 16:50:55
 * Copyright Jaime Junior
 */
package Adecot.Caminhao;

import Adecot.*;
import Controller.CaminhaoBO;
import Controller.CarretaBO;
import Controller.EmpresaBO;
import Controller.Facade.IceDecorator;
import Controller.Facade.ValidaFacade;
import Model.Caminhao;
import Model.Carreta;
import Model.Empresa;
import Report.XML.CriaQuery;
import Report.XML.ManipulaXML;
import Report.XML.Relatorio;
import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.icesoft.faces.component.ext.HtmlOutputText;
import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
import com.icesoft.faces.component.ext.HtmlSelectOneRadio;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectedData;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectionItems;
import com.icesoft.faces.component.jsfcl.data.PopupBean;
import com.icesoft.faces.component.panellayout.PanelLayout;
import com.icesoft.faces.component.panelpopup.PanelPopup;
import com.icesoft.faces.component.selectinputtext.SelectInputText;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.DoubleRangeValidator;
import Adecot.Vendas.VendaEmpresaCadastrar;
import Adecot.Vendas.VendaAssociadoCadastrar;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 */
public class CaminhaoCadastrar extends AbstractPageBean {
   // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

   private int __placeholder;

   /**
    * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
    * This method is automatically generated, so any user-specified code inserted
    * here is subject to being replaced.</p>
    */
   private void _init() throws Exception {
   }
   private boolean parar;

   public boolean isParar() {
      return parar;
   }

   public void setParar(boolean parar) {
      this.parar = parar;
   }
   private DefaultSelectionItems campoBuscaCaminhao;

   public DefaultSelectionItems getCampoBuscaCaminhao() {
      return campoBuscaCaminhao;
   }

   public void setCampoBuscaCaminhao(DefaultSelectionItems campoBuscaCaminhao) {
      this.campoBuscaCaminhao = campoBuscaCaminhao;
   }
   private DefaultSelectedData proprietarioSelecionado = new DefaultSelectedData();

   public DefaultSelectedData getProprietarioSelecionado() {
      return proprietarioSelecionado;
   }

   public void setProprietarioSelecionado(DefaultSelectedData dsd) {
      this.proprietarioSelecionado = dsd;
   }
   private DefaultSelectionItems proprietarios = new DefaultSelectionItems();

   public DefaultSelectionItems getProprietarios() {
      return proprietarios;
   }

   public void setProprietarios(DefaultSelectionItems dsi) {
      this.proprietarios = dsi;
   }
   private HtmlSelectOneMenu comboProprietario = new HtmlSelectOneMenu();

   public HtmlSelectOneMenu getComboProprietario() {
      return comboProprietario;
   }

   public void setComboProprietario(HtmlSelectOneMenu hsom) {
      this.comboProprietario = hsom;
   }
   private DefaultSelectedData tipoSelecionado = new DefaultSelectedData();

   public DefaultSelectedData getTipoSelecionado() {
      return tipoSelecionado;
   }

   public void setTipoSelecionado(DefaultSelectedData dsd) {
      this.tipoSelecionado = dsd;
   }
   private DefaultSelectionItems tipos = new DefaultSelectionItems();

   public DefaultSelectionItems getTipos() {
      return tipos;
   }

   public void setTipos(DefaultSelectionItems dsi) {
      this.tipos = dsi;
   }
   private HtmlSelectOneRadio radioTipo = new HtmlSelectOneRadio();

   public HtmlSelectOneRadio getRadioTipo() {
      return radioTipo;
   }

   public void setRadioTipo(HtmlSelectOneRadio hsor) {
      this.radioTipo = hsor;
   }
   private PanelLayout painelCarreta = new PanelLayout();

   public PanelLayout getPainelCarreta() {
      return painelCarreta;
   }

   public void setPainelCarreta(PanelLayout pl) {
      this.painelCarreta = pl;
   }
   private PanelLayout painelCaminhao = new PanelLayout();

   public PanelLayout getPainelCaminhao() {
      return painelCaminhao;
   }

   public void setPainelCaminhao(PanelLayout pl) {
      this.painelCaminhao = pl;
   }
   private DefaultSelectedData empresaCarretaSelecionada = new DefaultSelectedData();

   public DefaultSelectedData getEmpresaCarretaSelecionada() {
      return empresaCarretaSelecionada;
   }

   public void setEmpresaCarretaSelecionada(DefaultSelectedData dsd) {
      this.empresaCarretaSelecionada = dsd;
   }
   private DefaultSelectionItems empresaCarretas = new DefaultSelectionItems();

   public DefaultSelectionItems getEmpresaCarretas() {
      return empresaCarretas;
   }

   public void setEmpresaCarretas(DefaultSelectionItems dsi) {
      this.empresaCarretas = dsi;
   }
   private HtmlInputText campoModelo = new HtmlInputText();

   public HtmlInputText getCampoModelo() {
      return campoModelo;
   }

   public void setCampoModelo(HtmlInputText hit) {
      this.campoModelo = hit;
   }
   private HtmlInputText campoAno = new HtmlInputText();

   public HtmlInputText getCampoAno() {
      return campoAno;
   }

   public void setCampoAno(HtmlInputText hit) {
      this.campoAno = hit;
   }
   private HtmlInputText placaCaminhao = new HtmlInputText();

   public HtmlInputText getPlacaCaminhao() {
      return placaCaminhao;
   }

   public void setPlacaCaminhao(HtmlInputText hit) {
      this.placaCaminhao = hit;
   }
   private HtmlInputText campoEixo = new HtmlInputText();

   public HtmlInputText getCampoEixo() {
      return campoEixo;
   }

   public void setCampoEixo(HtmlInputText hit) {
      this.campoEixo = hit;
   }
   private HtmlInputText chassiCaminhao = new HtmlInputText();

   public HtmlInputText getChassiCaminhao() {
      return chassiCaminhao;
   }

   public void setChassiCaminhao(HtmlInputText hit) {
      this.chassiCaminhao = hit;
   }
   private HtmlInputText campoCapacidadeMax = new HtmlInputText();

   public HtmlInputText getCampoCapacidadeMax() {
      return campoCapacidadeMax;
   }

   public void setCampoCapacidadeMax(HtmlInputText hit) {
      this.campoCapacidadeMax = hit;
   }
   private HtmlInputText campoModeloCarreta = new HtmlInputText();

   public HtmlInputText getCampoModeloCarreta() {
      return campoModeloCarreta;
   }

   public void setCampoModeloCarreta(HtmlInputText hit) {
      this.campoModeloCarreta = hit;
   }
   private HtmlInputText campoAnoCarreta = new HtmlInputText();

   public HtmlInputText getCampoAnoCarreta() {
      return campoAnoCarreta;
   }

   public void setCampoAnoCarreta(HtmlInputText hit) {
      this.campoAnoCarreta = hit;
   }
   private HtmlInputText placaCarreta = new HtmlInputText();

   public HtmlInputText getPlacaCarreta() {
      return placaCarreta;
   }

   public void setPlacaCarreta(HtmlInputText hit) {
      this.placaCarreta = hit;
   }
   private HtmlInputText campoEixoCarreta = new HtmlInputText();

   public HtmlInputText getCampoEixoCarreta() {
      return campoEixoCarreta;
   }

   public void setCampoEixoCarreta(HtmlInputText hit) {
      this.campoEixoCarreta = hit;
   }
   private HtmlInputText campoCapacidadeMaxCarreta = new HtmlInputText();

   public HtmlInputText getCampoCapacidadeMaxCarreta() {
      return campoCapacidadeMaxCarreta;
   }

   public void setCampoCapacidadeMaxCarreta(HtmlInputText hit) {
      this.campoCapacidadeMaxCarreta = hit;
   }
   private HtmlSelectOneMenu comboEmpresaCarreta = new HtmlSelectOneMenu();

   public HtmlSelectOneMenu getComboEmpresaCarreta() {
      return comboEmpresaCarreta;
   }

   public void setComboEmpresaCarreta(HtmlSelectOneMenu hsom) {
      this.comboEmpresaCarreta = hsom;
   }
   private HtmlInputText marcaCarreta = new HtmlInputText();

   public HtmlInputText getMarcaCarreta() {
      return marcaCarreta;
   }

   public void setMarcaCarreta(HtmlInputText hit) {
      this.marcaCarreta = hit;
   }
   private PopupBean panelPopup1Bean = new PopupBean();

   public PopupBean getPanelPopup1Bean() {
      return panelPopup1Bean;
   }

   public void setPanelPopup1Bean(PopupBean pb) {
      this.panelPopup1Bean = pb;
   }
   private PanelPopup painelSair = new PanelPopup();

   public PanelPopup getPainelSair() {
      return painelSair;
   }

   public void setPainelSair(PanelPopup pp) {
      this.painelSair = pp;
   }
   private PopupBean panelPopup1Bean1 = new PopupBean();

   public PopupBean getPanelPopup1Bean1() {
      return panelPopup1Bean1;
   }

   public void setPanelPopup1Bean1(PopupBean pb) {
      this.panelPopup1Bean1 = pb;
   }
   private SelectInputText campoBuscaNome = new SelectInputText();

   public SelectInputText getCampoBuscaNome() {
      return campoBuscaNome;
   }

   public void setCampoBuscaNome(SelectInputText sit) {
      this.campoBuscaNome = sit;
   }
   private PopupBean panelPopup1Bean2 = new PopupBean();

   public PopupBean getPanelPopup1Bean2() {
      return panelPopup1Bean2;
   }

   public void setPanelPopup1Bean2(PopupBean pb) {
      this.panelPopup1Bean2 = pb;
   }
   private PanelPopup painelConsultar = new PanelPopup();

   public PanelPopup getPainelConsultar() {
      return painelConsultar;
   }

   public void setPainelConsultar(PanelPopup pp) {
      this.painelConsultar = pp;
   }
   private PanelPopup painelConsulta = new PanelPopup();

   public PanelPopup getPainelConsulta() {
      return painelConsulta;
   }

   public void setPainelConsulta(PanelPopup pp) {
      this.painelConsulta = pp;
   }
   private HtmlOutputText msgPainelAviso = new HtmlOutputText();

   public HtmlOutputText getMsgPainelAviso() {
      return msgPainelAviso;
   }

   public void setMsgPainelAviso(HtmlOutputText hot) {
      this.msgPainelAviso = hot;
   }
   private HtmlCommandButton botaoAvisoSim = new HtmlCommandButton();

   public HtmlCommandButton getBotaoAvisoSim() {
      return botaoAvisoSim;
   }

   public void setBotaoAvisoSim(HtmlCommandButton hcb) {
      this.botaoAvisoSim = hcb;
   }
   private HtmlCommandButton botaoAvisoNao = new HtmlCommandButton();

   public HtmlCommandButton getBotaoAvisoNao() {
      return botaoAvisoNao;
   }

   public void setBotaoAvisoNao(HtmlCommandButton hcb) {
      this.botaoAvisoNao = hcb;
   }
   private SelectInputText campoBusca = new SelectInputText();

   public SelectInputText getCampoBusca() {
      return campoBusca;
   }

   public void setCampoBusca(SelectInputText sit) {
      this.campoBusca = sit;
   }
   private PanelPopup painelAviso = new PanelPopup();

   public PanelPopup getPainelAviso() {
      return painelAviso;
   }

   public void setPainelAviso(PanelPopup pp) {
      this.painelAviso = pp;
   }
   private HtmlCommandButton botaoLimpar = new HtmlCommandButton();

   public HtmlCommandButton getBotaoLimpar() {
      return botaoLimpar;
   }

   public void setBotaoLimpar(HtmlCommandButton hcb) {
      this.botaoLimpar = hcb;
   }
   private PopupBean panelPopup1Bean3 = new PopupBean();

   public PopupBean getPanelPopup1Bean3() {
      return panelPopup1Bean3;
   }

   public void setPanelPopup1Bean3(PopupBean pb) {
      this.panelPopup1Bean3 = pb;
   }
   private PanelPopup painelMensagem = new PanelPopup();

   public PanelPopup getPainelMensagem() {
      return painelMensagem;
   }

   public void setPainelMensagem(PanelPopup pp) {
      this.painelMensagem = pp;
   }
   private HtmlOutputText msgConsultaTitulo = new HtmlOutputText();

   public HtmlOutputText getMsgConsultaTitulo() {
      return msgConsultaTitulo;
   }

   public void setMsgConsultaTitulo(HtmlOutputText hot) {
      this.msgConsultaTitulo = hot;
   }
   private HtmlCommandButton botaoConsultaOk = new HtmlCommandButton();

   public HtmlCommandButton getBotaoConsultaOk() {
      return botaoConsultaOk;
   }

   public void setBotaoConsultaOk(HtmlCommandButton hcb) {
      this.botaoConsultaOk = hcb;
   }
   private HtmlCommandButton botaoSairSim = new HtmlCommandButton();

   public HtmlCommandButton getBotaoSairSim() {
      return botaoSairSim;
   }

   public void setBotaoSairSim(HtmlCommandButton hcb) {
      this.botaoSairSim = hcb;
   }
   private HtmlOutputText msgMensagemResultado = new HtmlOutputText();

   public HtmlOutputText getMsgMensagemResultado() {
      return msgMensagemResultado;
   }

   public void setMsgMensagemResultado(HtmlOutputText hot) {
      this.msgMensagemResultado = hot;
   }
   private HtmlOutputText msgMensagemOperacao = new HtmlOutputText();

   public HtmlOutputText getMsgMensagemOperacao() {
      return msgMensagemOperacao;
   }

   public void setMsgMensagemOperacao(HtmlOutputText hot) {
      this.msgMensagemOperacao = hot;
   }
   private HtmlCommandButton botaoMensagemOk = new HtmlCommandButton();

   public HtmlCommandButton getBotaoMensagemOk() {
      return botaoMensagemOk;
   }

   public void setBotaoMensagemOk(HtmlCommandButton hcb) {
      this.botaoMensagemOk = hcb;
   }
   private HtmlCommandButton botaoAlterar = new HtmlCommandButton();

   public HtmlCommandButton getBotaoAlterar() {
      return botaoAlterar;
   }

   public void setBotaoAlterar(HtmlCommandButton hcb) {
      this.botaoAlterar = hcb;
   }
   private HtmlCommandButton botaoCadastrar1 = new HtmlCommandButton();

   public HtmlCommandButton getBotaoCadastrar1() {
      return botaoCadastrar1;
   }

   public void setBotaoCadastrar1(HtmlCommandButton hcb) {
      this.botaoCadastrar1 = hcb;
   }
   private HtmlInputText chassiCarreta = new HtmlInputText();

   public HtmlInputText getChassiCarreta() {
      return chassiCarreta;
   }

   public void setChassiCarreta(HtmlInputText hit) {
      this.chassiCarreta = hit;
   }
   private DoubleRangeValidator doubleRangeValidator1 = new DoubleRangeValidator();

   public DoubleRangeValidator getDoubleRangeValidator1() {
      return doubleRangeValidator1;
   }

   public void setDoubleRangeValidator1(DoubleRangeValidator drv) {
      this.doubleRangeValidator1 = drv;
   }
   private HtmlInputText marcaCaminhao = new HtmlInputText();

   public HtmlInputText getMarcaCaminhao() {
      return marcaCaminhao;
   }

   public void setMarcaCaminhao(HtmlInputText hit) {
      this.marcaCaminhao = hit;
   }

   // </editor-fold>
   /**
    * <p>Construct a new Page bean instance.</p>
    */
   public CaminhaoCadastrar() {
   }

   /**
    * <p>Callback method that is called whenever a page is navigated to,
    * either directly via a URL, or indirectly via page navigation.
    * Customize this method to acquire resources that will be needed
    * for event handlers and lifecycle methods, whether or not this
    * page is performing post back processing.</p>
    *
    * <p>Note that, if the current request is a postback, the property
    * values of the components do <strong>not</strong> represent any
    * values submitted with this request.  Instead, they represent the
    * property values that were saved for this view when it was rendered.</p>
    */
   @Override
   public void init() {
      // Perform initializations inherited from our superclass
      super.init();

      // Perform application initialization that must complete
      // *before* managed components are initialized
      // TODO - add your own initialiation code here

      // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
      // Initialize automatically managed components
      // *Note* - this logic should NOT be modified
      try {
         _init();

      } catch (Exception e) {
         log("CaminhaoCadastrar Initialization Failure", e);
         throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
      }
      try {
      } catch (Exception ex) {
      }
      this.setEmpresaCarretas(new IceDecorator(EmpresaBO.class).montaCombo());
      this.setProprietarios(new IceDecorator(EmpresaBO.class).montaCombo());

      tipos.clear();
      tipos.add(new SelectItem("Simples", "Caminhão Simples"));
      tipos.add(new SelectItem("Carreta", "Carreta"));
      radioTipo.setValue("Simples");

      painelCarreta.setRendered(false);
      painelCaminhao.setRendered(true);
      painelSair.setRendered(false);
      painelConsulta.setRendered(false);
      painelAviso.setRendered(false);
      painelMensagem.setRendered(false);
   // </editor-fold>
   // Perform application initialization that must complete
   // *after* managed components are initialized
   // TODO - add your own initialization code here
   }

   /**
    * <p>Callback method that is called after the component tree has been
    * restored, but before any event processing takes place.  This method
    * will <strong>only</strong> be called on a postback request that
    * is processing a form submit.  Customize this method to allocate
    * resources that will be required in your event handlers.</p>
    */
   @Override
   public void preprocess() {
   }

   /**
    * <p>Callback method that is called just before rendering takes place.
    * This method will <strong>only</strong> be called for the page that
    * will actually be rendered (and not, for example, on a page that
    * handled a postback and then navigated to a different page).  Customize
    * this method to allocate resources that will be required for rendering
    * this page.</p>
    */
   @Override
   public void prerender() {
   }

   /**
    * <p>Callback method that is called after rendering is completed for
    * this request, if <code>init()</code> was called (regardless of whether
    * or not this was the page that was actually rendered).  Customize this
    * method to release resources acquired in the <code>init()</code>,
    * <code>preprocess()</code>, or <code>prerender()</code> methods (or
    * acquired during execution of an event handler).</p>
    */
   @Override
   public void destroy() {
   }

   /**
    * <p>Retornar uma referência para o Bean de dados limitados.</p>
    *
    * @retorna uma referência para o bean de dados limitados
    */
   protected SessionBean1 getSessionBean1() {
      return (SessionBean1) getBean("SessionBean1");

   }

   /**
    * <p>Retornar uma referência para o Bean de dados limitados.</p>
    *
    * @retorna uma referência para o bean de dados limitados
    */
   protected RequestBean1 getRequestBean1() {
      return (RequestBean1) getBean("RequestBean1");
   }

   /**
    * <p>Retornar uma referência para o Bean de dados limitados.</p>
    *
    * @retorna uma referência para o bean de dados limitados
    */
   protected ApplicationBean1 getApplicationBean1() {
      return (ApplicationBean1) getBean("ApplicationBean1");
   }

   //ação dos botões do painel de opções
   public String botaoCadastrar1_action() {
      String opcao = radioTipo.getValue().toString();
      Caminhao caminhao = (Caminhao) getBean("Caminhao");
      try {

         if (opcao.equals("Simples")) {
            Empresa empresa = (Empresa) new IceDecorator(EmpresaBO.class).retornaObjetoCodigo("codEmpresa",
                    Integer.parseInt(comboProprietario.getValue().toString()));
            caminhao.setEmpresa(empresa);
            caminhao.setTipo("simples");
            caminhao.setAtivo(true);

            new IceDecorator(CaminhaoBO.class).salvar(caminhao);
         } else if (opcao.equals("Carreta")) {
            Carreta carreta = (Carreta) getBean("Carreta");
            Empresa empresa = (Empresa) new IceDecorator(EmpresaBO.class).retornaObjetoCodigo("codEmpresa",
                    Integer.parseInt(comboEmpresaCarreta.getValue().toString()));
            carreta.setEmpresa(empresa);
            carreta.setAtivo(true);
            caminhao.setTipo("carreta");

            new IceDecorator(CarretaBO.class).salvar(carreta);
         }
         limparCampos();

         radioTipo.setValue("Simples");
         painelCaminhao.setRendered(true);
         painelCarreta.setRendered(false);

         painelMensagem.setRendered(true);
      } catch (Exception e) {
         msgMensagemResultado.setValue("Não Foi Possível Realizar a Operação");
         msgMensagemOperacao.setValue("Verificar se há:" + e.getMessage());
         painelMensagem.setRendered(true);
      }
      return null;
   }

   public String botaoNao_action() {
      painelSair.setRendered(false);
      return null;
   }

   public String botaoConsultar_action() {
      String opcao = radioTipo.getValue().toString();

      if (opcao.equals("Simples")) {
         msgConsultaTitulo.setValue("Digite a placa do caminhao a ser consultada");
         painelConsulta.setRendered(true);
      } else if (opcao.equals("Carreta")) {
         msgConsultaTitulo.setValue("Digite a placa da carreta a ser consultada");
         painelConsulta.setRendered(true);
      }
      return null;
   }

   public String botaoAlterar_action() {
      habilitarCamposCaminhao();
      habilitarCamposCarreta();
      setParar(true);
      return null;
   }

   public String botaoSair_action() {
      painelSair.setRendered(true);
      return null;
   }
   //ação dos campos

   public void campoBusca_processValueChange(ValueChangeEvent vce) {
      String opcao = radioTipo.getValue().toString();

      try {
         if (opcao.equals("Simples")) {
            this.setCampoBuscaCaminhao(new IceDecorator(CaminhaoBO.class).consultaIncremental("placaCaminhao", campoBusca.getValue().toString()));
         } else {
            this.setCampoBuscaCaminhao(new IceDecorator(CarretaBO.class).consultaIncremental("placaCarreta", campoBusca.getValue().toString()));
         }
      } catch (Exception e) {
      }
   }

   public void radioTipo_processValueChange(ValueChangeEvent vce) {
      String opcao = radioTipo.getValue().toString();
      campoBusca.resetValue();

      if (opcao.equals("Carreta")) {
         painelCaminhao.setRendered(false);
         painelCarreta.setRendered(true);

      } else {
         painelCaminhao.setRendered(true);
         painelCarreta.setRendered(false);
      }

   }

   //m´[etodos par uso dos botões
   public void limparCampos() {
      FacesContext.getCurrentInstance().getExternalContext().getRequestMap().remove("Caminhao");
      FacesContext.getCurrentInstance().getExternalContext().getRequestMap().remove("Carreta");

      habilitarCamposCaminhao();
      habilitarCamposCarreta();
      campoAno.resetValue();
      campoAnoCarreta.resetValue();
      campoBusca.resetValue();
      campoBuscaNome.resetValue();
      campoCapacidadeMax.resetValue();
      campoCapacidadeMaxCarreta.resetValue();
      chassiCaminhao.resetValue();
      campoEixo.resetValue();
      chassiCarreta.resetValue();
      campoEixoCarreta.resetValue();
      marcaCaminhao.resetValue();
      marcaCarreta.resetValue();
      placaCaminhao.resetValue();
      placaCarreta.resetValue();
      comboEmpresaCarreta.resetValue();
      comboProprietario.resetValue();
      campoModelo.resetValue();
      campoModeloCarreta.resetValue();
      parar = false;
      botaoAlterar.setDisabled(true);
   }

   public void habilitarCamposCarreta() {

      this.campoAnoCarreta.setDisabled(false);
      this.chassiCarreta.setDisabled(false);
      this.campoCapacidadeMaxCarreta.setDisabled(false);
      this.campoEixoCarreta.setDisabled(false);
      this.marcaCarreta.setDisabled(false);
      this.campoModeloCarreta.setDisabled(false);
      this.placaCarreta.setDisabled(false);
      this.comboEmpresaCarreta.setDisabled(false);

   }

   public void desabilitarCamposCarreta() {

      this.campoAnoCarreta.setDisabled(true);
      this.chassiCarreta.setDisabled(true);
      this.campoCapacidadeMaxCarreta.setDisabled(true);
      this.campoEixoCarreta.setDisabled(true);
      this.marcaCarreta.setDisabled(true);
      this.campoModeloCarreta.setDisabled(true);
      this.placaCarreta.setDisabled(true);
      this.comboEmpresaCarreta.setDisabled(true);
   }

   public void habilitarCamposCaminhao() {
      this.campoAno.setDisabled(false);
      this.chassiCaminhao.setDisabled(false);
      this.campoCapacidadeMax.setDisabled(false);
      this.campoEixo.setDisabled(false);
      this.marcaCaminhao.setDisabled(false);
      this.campoModelo.setDisabled(false);
      this.placaCaminhao.setDisabled(false);
      this.comboProprietario.setDisabled(false);

   }

   public void desabilitarCamposCaminhao() {
      this.campoAno.setDisabled(true);
      this.chassiCaminhao.setDisabled(true);
      this.campoCapacidadeMax.setDisabled(true);
      this.campoEixo.setDisabled(true);
      this.marcaCaminhao.setDisabled(true);
      this.campoModelo.setDisabled(true);
      this.placaCaminhao.setDisabled(true);
      this.comboProprietario.setDisabled(true);
   }

   //ação dos botões dos pop ups
   public String botaoLimpar_action() {
      limparCampos();
      return null;
   }

   public String botaoSairSim_action() {
      //return null means stay on the same page
      return "menu";
   }

   public String botaoSairNao_action() {
      painelSair.setRendered(false);
      return null;
   }

   public String botaoConsultaCancelar_action() {
      painelConsulta.setRendered(false);
      return null;
   }

   public String botaoConsultaOk_action() {
      String opcao = radioTipo.getValue().toString();
      try {
         if (opcao.equals("Simples")) {
            Caminhao caminhao = (Caminhao) new IceDecorator(CaminhaoBO.class).retornaObjeto("placaCaminhao", campoBusca.getValue().toString());
            limparCampos();
            setBean("Caminhao", caminhao);
            comboProprietario.setValue(caminhao.getEmpresa().getCodEmpresa());
            painelConsulta.setRendered(false);
            desabilitarCamposCaminhao();

         } else if (opcao.equals("Carreta")) {
            Carreta carreta = (Carreta) new IceDecorator(CarretaBO.class).retornaObjeto("placaCarreta", campoBusca.getValue().toString());
            limparCampos();
            setBean("Carreta", carreta);
            comboEmpresaCarreta.setValue(carreta.getEmpresa().getCodEmpresa());
            painelConsulta.setRendered(false);
            desabilitarCamposCarreta();
         }
         botaoAlterar.setDisabled(false);
      } catch (Exception e) {

         painelAviso.setRendered(true);

      }
      return null;
   }

   public String botaoAvisoSim_action() {
      painelAviso.setRendered(false);
      painelConsulta.setRendered(true);
      return null;
   }

   public String botaoAvisoNao_action() {
      painelAviso.setRendered(false);
      painelConsulta.setRendered(false);
      return null;
   }

   public String botaoMensagemOk_action() {
      painelMensagem.setRendered(false);
      return null;
   }

   public String botaoNovo_action() {
      limparCampos();
      return null;
   }

   public void validateCampoUnico(FacesContext context, UIComponent component, Object value) {
      Class classeBO;
      String opcao = radioTipo.getValue().toString();
      if (opcao.equals("Simples")) {
         classeBO = CaminhaoBO.class;
      } else {
         classeBO = CarretaBO.class;
      }
      new ValidaFacade().validateCampoUnico(context, component, value, classeBO, parar);
   }

   public String botaoImprimir_action() {

      ManipulaXML manipulaXML = new ManipulaXML();
      CriaQuery criaQuery = new CriaQuery();
      Relatorio relatorio = new Relatorio();

      String opcao = radioTipo.getValue().toString();
      try {
         if (opcao.equals("Simples")) {
            Caminhao caminhao = (Caminhao) getBean("Caminhao");
            //if para relatório completo de Caminhões
            manipulaXML.modificaXML("Relatorios\\Caminhao", criaQuery.criaQueryCaminhao(comboProprietario.getValue().toString(), placaCaminhao.getValue().toString()));
            relatorio.geraJrprint("Relatorios\\Caminhao");
            relatorio.geraRelatorioPDF("Relatorios\\Caminhao");
            java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
            desktop.open(new File("Relatorios\\Caminhao.pdf"));//return null means stay on the same page
         } else {
            Carreta carreta = (Carreta) getBean("Carreta");

            //(comboTipoRelatorio.getValue().equals("Carretas")){
            System.out.println(carreta.getEmpresa().getNome());
            System.out.println(placaCarreta.getValue().toString());
            System.out.println(criaQuery.criaQueryCarreta(carreta.getEmpresa().getNome(), placaCarreta.getValue().toString()));
            manipulaXML.modificaXML("Relatorios\\Carreta", criaQuery.criaQueryCarreta(comboEmpresaCarreta.getValue().toString(), placaCarreta.getValue().toString()));
            relatorio.geraJrprint("Relatorios\\Carreta");
            relatorio.geraRelatorioPDF("Relatorios\\Carreta");
            java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
            desktop.open(new File("Relatorios\\Carreta.pdf"));//return null means stay on the same page
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }

    public void campoAno_validate(FacesContext context, UIComponent component, Object value) {
        new ValidaFacade().validateNum(context, component, value, CaminhaoBO.class, parar);
    }

    public void campoAnoCarreta_validate(FacesContext context, UIComponent component, Object value) {
        new ValidaFacade().validateNum(context, component, value, CarretaBO.class, parar);
    }

    public void campoEixo_validate(FacesContext context, UIComponent component, Object value) {
        new ValidaFacade().validateNum(context, component, value, CaminhaoBO.class, parar);
    }

    public void campoEixoCarreta_validate(FacesContext context, UIComponent component, Object value) {
        new ValidaFacade().validateNum(context, component, value, CarretaBO.class, parar);
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected VendaEmpresaCadastrar getVendas$VendaEmpresaCadastrar() {
        return (VendaEmpresaCadastrar) getBean("Vendas$VendaEmpresaCadastrar");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected VendaAssociadoCadastrar getVendas$VendaAssociadoCadastrar() {
        return (VendaAssociadoCadastrar) getBean("Vendas$VendaAssociadoCadastrar");
    }
}